package com.vsen.lpr.service;

import com.vsen.lpr.common.model.Response;
import com.vsen.lpr.common.utils.BeanCopyUtil;
import com.vsen.lpr.entity.Comment;
import com.vsen.lpr.entity.ext.UserCommentDo;
import com.vsen.lpr.mapper.CommentMapper;
import com.vsen.lpr.pojo.dto.CommentDto;
import com.vsen.lpr.pojo.vo.CommentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CommentService {

    @Autowired
    private CommentMapper commentMapper;

    public Response comment(CommentDto commentDto) {
        Comment comment = new Comment();
        BeanCopyUtil.copyFromSrcToDest(commentDto,comment);
        comment.setTime(new Date());
        commentMapper.insert(comment);
        return Response.success();
    }

    public Response<List<CommentVo>> commentList(CommentDto commentDto) {
        List<UserCommentDo> list = commentMapper.selectByProductId(commentDto.getProductId());
        List<CommentVo> result =  BeanCopyUtil.copyListFromSrcToDest(list,CommentVo.class);
        return Response.success(result);
    }
}
